﻿function formatAllUI() {
    autoFormatPage();
    //
    $("input.number").keydown(function (e) {
        var keyPressed;
        if (!e) var e = window.event;
        if (e.keyCode) keyPressed = e.keyCode;
        else if (e.which) keyPressed = e.which;
        var hasDecimalPoint = (($(this).val().split('.').length - 1) > 0);
        if (keyPressed == 46 || keyPressed == 8 || ((keyPressed == 190 || keyPressed == 110) && (!hasDecimalPoint)) || keyPressed == 9 || keyPressed == 27 || keyPressed == 13 ||
            // Allow: Ctrl+A
            (keyPressed == 65 && e.ctrlKey === true) ||
            // Allow: home, end, left, right
            (keyPressed >= 35 && keyPressed <= 39)) {
            return;
        }
        else {
            if (e.shiftKey || (keyPressed < 48 || keyPressed > 57) && (keyPressed < 96 || keyPressed > 105)) {
                e.preventDefault();
            }
        }
    }).keyup(function () {
        var x = $(this).val();
        $(this).val(x.toString().replace(/,/g, "").replace(/\B(?=(\d{3})+(?!\d))/g, ","));
    });
}

function autoFormatPage() {
    var theHeight = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
    var W_content = window.innerWidth - 20;
    var H_content = theHeight - 20;
    $("#swapper-page").width(W_content);
    $("#swapper-page").height(H_content);
    $("#swap-bartop").width(window.innerWidth - 18);

    $("#swap-content").width(window.innerWidth - 20);
    $("#swap-content").height(theHeight - 90);
    $("#swap-content").width(window.innerWidth - 20);
    $(".col-right").width(W_content - 310);
    $(".swap-product").height(theHeight - 185);
    $("ul.from").height(theHeight - 180);
}